package com.jxb.service;

import java.io.Serializable;

import javax.annotation.Resource;

import com.jxb.moniDubbo.OrderStream;
import com.jxb.moniDubbo.User;
import org.apache.dubbo.common.stream.StreamObserver;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.jxb.moniDubbo.UserService;

@Service
public class OrderService implements Serializable {

    @Resource
    private RestTemplate restTemplate;

    // @DubboReference(url = "rest://192.168.247.1:8080",protocol = "rest")
    @DubboReference
    // @DubboReference
    private UserService userService;

    public String createOrder(){
//         User user = restTemplate.getForObject("http://127.0.0.1:8089/user/1", User.class);
//         User user = userService.getUser("1");
        System.out.println("创建订单");

        // tripe协议的流式调用
//        userService.sayHelloServerStream("1111", new OrderStream());

        //trip协议调用双端流
        OrderStream orderStream = userService.sayHelloStream(new OrderStream());
        orderStream.onNext("123");
        orderStream.onCompleted();

        return " succeeded in creating the order";
    }
}